package com.shizhanzhe.zxbapp.home;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.widget.CircleImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YJ on 2018/10/23.
 */
public class InvitationAdapter extends RecyclerView.Adapter<InvitationAdapter.ViewHolder> {
    private Context mContext;
    private List<InviteFriend.DataBean> mData = new ArrayList<>();

    public InvitationAdapter(Context context) {
        mContext = context;
    }

    public void updateData(List<InviteFriend.DataBean> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            mData = dataSet;
            notifyDataSetChanged();
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_invite_friend, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        InviteFriend.DataBean dataBean = mData.get(position);
        Glide.with(mContext).load(Path.BASE_URL+dataBean.getAvatar()).into(holder.civ);
        holder.tvPhone.setText(dataBean.getMobile().substring(0,3) +"****" + dataBean.getMobile().substring(7,dataBean.getMobile().length()));
        holder.tv_nickname.setText(dataBean.getNickname());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        CircleImageView civ;
        TextView tvPhone;
        TextView tv_nickname;

        public ViewHolder(View itemView) {
            super(itemView);
            civ = itemView.findViewById(R.id.civ);
            tvPhone = itemView.findViewById(R.id.tv_phone);
            tv_nickname = itemView.findViewById(R.id.tv_nickname);
        }
    }
}
